class Supplement < Asset

  has_attached_file :attachment
                    #:url  => "/:basename.:extension"

  validates :name, :length => {:maximum => 100}, :allow_nil => true
  validates :description, :length => {:maximum => 250}
  validates :attachment_file_name, :presence => true unless lambda {|attr| attr.object.new_record?}
  validates_attachment_content_type :attachment, :content_type => ['text/plain' ,'application/mspowerpoint' ,'application/vnd.ms-powerpoint' ,'application/vnd.ms-excel' ,'application/x-msexcel' ,'application/ms-excel' ,'application/msexcel' ,'application/x-excel', 'application/msword', 'application/pdf', 'application/x-pdf', 'image/png', 'image/jpeg', 'image/gif', 'image/x-png']
  validate :attachment_check

  def attachment_check
    unless attachment.errors.empty?
      errors.add(:base, "Při ukládání přílohy ('#{attachment_file_name}') došlo k chybě.")
      false
    end
  end
end
